/*
 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * This file is part of Harmattan SmashMiner OpenGL game application.
 * 
 * Harmattan SmashMiner OpenGL Example Application version 1.0.0
 *  
 * Latest update: 15.4.2011
 *
 * The Harmattan SmashMiner OpenGL example application demonstrates how to use 
 * the OpenGL ES in Harmattan devices.
 *
 * This example is provided as a starting point for 3rd party
 * developers (you) to ease the implementation of OpenGL based 
 * games. Ideas, parts of code or methodologies that this
 * example application uses can be freely used without restrictions.
 *
 * See file README.txt how to build and compile this example application
 * in the Harmattan SDK environment. 
 * 
 * See file INSTALL.txt to find out what is required to run this
 * application and how to install the application to the device or
 * alternatively in QEMU-emulator.
 *
 * The LICENSE.txt file explains the license this software is provided
 * with. A copy of the same license is included in this source file.
 * 
 */

/*
 * Copyright (C) 2011 by Nokia Corporation.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#include "gamewidget.h"
#include "collectible.h"
#include "meteorshower.h"
#include "blackhole.h"
#include "comet.h"
#include "ufo.h"

#ifdef SMASHMINER_CONFIG_ENABLE_TESTINGMODE

void GameEngine::testingModeInit()
{
    static bool isAlreadyInitialized = false;
    if (isAlreadyInitialized)
        return;
    else
        isAlreadyInitialized = true;

    GameObjectStartParameters sp;

    // create a blackhole object.
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /*getStartParams(HorizontalDirection, 1.25f, sp);
    blackhole = new BlackHole(totalFrameCounter, rewindEnabled, 20.0f);
    blackhole->setPosX(sp.startX);
    blackhole->setPosY(sp.startY);
    blackhole->setVelX(sp.unitVelX * 2.0f);
    blackhole->setVelY(sp.unitVelY * 2.0f);*/

    // create a comet object.
    //^^^^^^^^^^^^^^^^^^^^^^^^
    /*getStartParams(AnyDirection, 1.25f, sp);
    // warning : comet growth rate(s) must be small compared to it's velocity.
    // if it grows faster than it moves, it will of course never get out of the screen!
    comet = new Comet(totalFrameCounter, rewindEnabled, totalTimeCounter, 4.0f, 10.0f, 2.0f);
    comet->setPosX(sp.startX);
    comet->setPosY(sp.startY);
    comet->setRotationAngle(sp.angle);
    comet->setVelX(sp.unitVelX * 8.0f);
    comet->setVelY(sp.unitVelY * 8.0f);*/

    // create a single MeteorShowers.
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/*  getStartParams(AnyDirection, 1.25f, sp);
    // warning : meteorshower growth rate must be small compared to velocity, so that
    // no free space will appear between the meteors (the player cannot fly there!).
    enemyList << new MeteorShower(totalFrameCounter, rewindEnabled, totalTimeCounter, 10.0f, 1.0f);
    enemyList.back()->setPosX(sp.startX);
    enemyList.back()->setPosY(sp.startY);
    enemyList.back()->setVelX(sp.unitVelX * 8.0f);
    enemyList.back()->setVelY(sp.unitVelY * 8.0f);  */

    // create many MeteorShowers.
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/*  getStartParams(AnyDirection, 1.25f, sp);
    // warning : meteorshower growth rate must be small compared to velocity, so that
    // no free space will appear between the meteors (the player cannot fly there!).
    const GLfloat initialRadius = 10.0f;
    const GLfloat tailDirectionX = sin(sp.angle + M_PI) * initialRadius * 2.2f;
    const GLfloat tailDirectionY = cos(sp.angle + M_PI) * initialRadius * 2.2f;
    const GLfloat sideDirectionX = sin(sp.angle + M_PI * 0.50f) * initialRadius * 2.0f;
    const GLfloat sideDirectionY = cos(sp.angle + M_PI * 0.50f) * initialRadius * 2.0f;
    const FPtype startPos[2] = { sp.startX, sp.startY };
    const FPtype centerPos[2] = { (sp.startX + sp.endX) * 0.5f, (sp.startY + sp.endY) * 0.5f };
    const GLfloat meteorShowerRadiusChange = 1.0f;
    const GLfloat meteorShowerSpeed = 7.5f;
    for (int i = 0;i < 10;i++) {
        MeteorShower *ms = new MeteorShower(totalFrameCounter, rewindEnabled,
                totalTimeCounter, initialRadius, meteorShowerRadiusChange);
        ms->setStartAndCenterPositions(startPos, centerPos);

        const GLfloat random = getRandomF() - 0.50f;
        const GLfloat posX = sp.startX + i * tailDirectionX + random * sideDirectionX;
        const GLfloat posY = sp.startY + i * tailDirectionY + random * sideDirectionY;

        ms->setPosX(posX);
        ms->setPosY(posY);

        ms->setVelX(sp.unitVelX * meteorShowerSpeed);
        ms->setVelY(sp.unitVelY * meteorShowerSpeed);

        enemyList.append(ms);
    }   */

    // create an UFO object.
    //^^^^^^^^^^^^^^^^^^^^^^^
/*  FPtype margin;
    Ufo::UfoMovement movement;
    if (getRandomF() < 0.50) {
        // for SineMovement use margin = 1.25 which is a normal value.
        margin = 1.25f;
        movement = Ufo::SineMovement;
    }
    else {
        // for CircularMovement use margin = 1.00 which is a smaller value.
        // this is to compensate the "backward" movement involved in CircularMovement.
        // if the complensation is not large enough, the UFO may be removed immediately.
        // see GameEngine::removeUnnecessaryObjects() and GameEngine::getStartParams().
        margin = 1.00f;
        movement = Ufo::CircularMovement;
    }
    getStartParams(AnyDirection, margin, sp);
    enemyList << new Ufo(totalFrameCounter, rewindEnabled, movement, sp.angle);
    enemyList.back()->setPosX(sp.startX);
    enemyList.back()->setPosY(sp.startY);   */

    //missileSpeed = 1.0f;
    //missileIncidence = 1.0f;
    //missileGuidance = 1.0;

    // create Bomb object(s).
    //^^^^^^^^^^^^^^^^^^^^^^^^
/*  for (int i = 0;i < 5;i++) {
        getStartParams(AnyDirection, 1.00f, sp);
        collectibleList << new Bomb(totalFrameCounter, rewindEnabled, GameObjectRadiusBomb);
        collectibleList.back()->setPosX(sp.startX);
        collectibleList.back()->setPosY(sp.startY);
        collectibleList.back()->setVelX(sp.unitVelX * 2.0f);
        collectibleList.back()->setVelY(sp.unitVelY * 2.0f);
    }   */

    // change some miner settings.
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    skipMinerCollision = true;
    miner->setPosX(+40.0f);
    miner->setPosY(-40.0f);
}

void GameWidget::testingModeSteering(FPtype time)
{
    engine->setSteeringX(0.0);
    engine->setSteeringY(0.0);

    // do steering at x-direction between 3-5 seconds.

    if (time > 1.0 && time < 15.0)
        engine->setSteeringX(+2.50);

    // do steering at y-direction between 5-6 seconds.

    if (time > 1.0 && time < 15.0)
        engine->setSteeringY(+2.35);

    // switch shipmode at time = 3 seconds.

    static bool modeSwitchA = true;
    if (modeSwitchA && time > 3.0) {
        engine->changeShipModeDelayed();
        modeSwitchA = false;
    }

    // add more stering commands...
    // add more stering commands...
    // add more stering commands...
}

#endif  // SMASHMINER_CONFIG_ENABLE_TESTINGMODE
